package com.dau.api.controller;

import com.dau.api.annotation.RepeatSubmit;
import com.dau.common.result.R;
import com.dau.entity.customer.OrderInfo;
import com.dau.service.customer.order.OrderService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("api/order")
public class ApiOrderController {
    @Resource
    private OrderService orderService;


    /**
     * 下订单
     *
     * @param order 订单信息
     * @return {@link R }<{@link String }>
     */
    @PostMapping("/placeAnOrder")
    @RepeatSubmit(interval = 500, timeUnit = TimeUnit.MILLISECONDS)
    public R<OrderInfo> placeAnOrder(@RequestBody @Validated OrderInfo order) {
        return R.success(orderService.placeAnOrder(order));
    }
}
